#include"../mqserver/mq_exchage.hpp"
#include<gtest/gtest.h>
bitmq::ExchageManger::ptr emp;
class ExchageTest:public testing::Environment{
    public:
    virtual void SetUp()override
    {
        emp=std::make_shared<bitmq::ExchageManger>("./data/meta.db");
        std::cout<<"初始化数据成功！"<<std::endl;
    }
    virtual void TearDown()override
    {
        //emp->clear();
    }
};

TEST(exchage_test1,insert_test)
{
    std::unordered_map<std::string,std::string> map{{"k1","v1"},{"k2","v2"},{"k3","v3"}};
    emp->declareExchage("exchage1",bitmq::ExchageType::DERICT,true,false,map);
    emp->declareExchage("exchage2",bitmq::ExchageType::DERICT,true,false,map);
    emp->declareExchage("exchage3",bitmq::ExchageType::DERICT,true,false,map);
    ASSERT_EQ(emp->size(),3);
}
TEST(exchage_test2,select_test)
{
    bitmq::Exchage::ptr e=emp->selectExchage("exchage2");
    ASSERT_EQ(e->_name,"exchage2");
    ASSERT_EQ(e->_type,bitmq::ExchageType::DERICT);
    ASSERT_EQ(e->_durable,true);
    ASSERT_EQ(e->_auto_delete,false);
    //ASSERT_EQ(e->getArgs(),"k2=v2&");
}
TEST(exchage_test3,remove_test)
{
    emp->deleteExchage("exchage2");
    ASSERT_EQ(emp->size(),2);
    ASSERT_EQ(emp->exits("exchange2"), false);
}

int main(int argc,char* argv[])
{
    testing::InitGoogleTest(&argc,argv);
    testing::AddGlobalTestEnvironment(new ExchageTest);
    int ret=RUN_ALL_TESTS();
    return 0;
}